{assign $oui='selected="selected"'}
{literal}
    <style type="text/css">
        #liste_illustration input[type="text"].search{
            width:100px;
        }
    </style>
{/literal}
<div id="main_container">
    {$oZoneHeader}
    <div class="main_content">
        {$oZoneTopMenu}
        <div class="center_content">  
            <div class="left_content">
                {$oZoneLeftMenu}
                {$oZoneModeleLeft}
            </div>
    
        <div class="right_content">
            <input type="hidden" id='path' value="{$photosPath}" />
            <input type="hidden" id="delImage" value="{$j_basepath}design/front/images/DeleteRed.png" />
            <input type="hidden" id="zBasePath" value="{$j_basepath}" />
            <input type="hidden" id="noImage" value="{$j_basepath}design/front/images/no_image.jpg" />
                <form id="createForm" class="Gmodeles" action="{jurl 'essais~BoModele:saveChapitre', array('iTypeId'=>$oEssai->ess_iTypeId,'type'=>$type), false}" method="POST">   
                <input type="hidden" value="{$chap_name_id}"  name="chapNameId"/>
                <input type="hidden" value="{$chap_modele}"  name="chap_modele"/>
                <input type="hidden" value="{$iTypeId}"  name="iTypeId"/>
                <input type="hidden" value="{$iEssaiId}"  name="ess_id"/>
                <input type="hidden" value="{$chapitre[0]->chap_id}"  name="chap_id"/>
                <input type="hidden"  value="{$type}" name ="type"/>
                {if $type == 1}
                    {assign $title = 'CHAPITRE'}
                {else}
                    {assign $title = 'Ajouter une version à'}

                {/if}
                <h2>{$title} {if $type == 2} {$ttl} {else}{if isset($oEssai->ess_zSousTitre) && $oEssai->ess_zSousTitre}- {$oEssai->ess_zSousTitre}{/if}{/if}</h2>
                {if $type == 1}
                 <dl>
                    <dt><label>Titre : </label></dt>
                    <dd>
                     <select name="chap_name_id" validation="required" id="chap-title-list">
                            {foreach $chapitreTitre as $item}
                                {if $item->chap_name_id == $chapitre[0]->chap_name_id}  
                                      {assign $selected='selected="selected"'}
                                 {else}
                                      {assign $selected=''}
                                {/if}
                               
                                   <option value="{$item->chap_name_id}" {$selected}>{$item->chap_name}</option>
                            {/foreach}

                            {if !in_array($chapitre[0]->chap_name_id, $chapitreAutre) }
                                    {assign $oui='selected="selected"'}
                            {else}
                                    {assign $oui=''}
                            {/if}
                            <option value="0"{$oui}>Autre</option>


                    </select>
                    </dd>
                    <dd style="margin-left:15px">
                       {if !in_array($chapitre[0]->chap_name_id, $chapitreAutre) }
                         {if $chapitre[0]->type==1}
                            <input type="text"  name="chap_autre" value="{$chapitre[0]->chap_name}" id="chap-autre" />
                         {else}
                            <input type="text"  name="chap_autre" value="{$chapitre[0]->version_name}" id="chap-autre" />
                         {/if}
                       {else}
                         <input type="text" style="display:none;" name="chap_autre" value="" id="chap-autre" />
                       {/if}
                    </dd>
                        {literal}
                            <script type="text/javascript">
                                $(function () {
                                    $('#chap-title-list').change(function () {
                                        if ($(this).val() == '0')
                                        {
                                            $('#chap-autre').show();
                                        }
                                        else
                                        {
                                            $('#chap-autre').hide();
                                        }
                                    });
                                });
                            </script>
                        {/literal}
                  </dl>
                  {/if}
                  {if $type == 2}
                  <dl style="height:auto">
                    <dt><label>Titre : </label></dt>
                    <dd>
                    <input type="text"  name="chap_autre" value="{$chapitre[0]->version_name}" id="chap-autre" />
                    </dd>
                  </dl>
                  {/if}
                  <dl style="height:auto">
                    <!--<dt><label>Texte : </label></dt>-->
                    <dd style="width:600px;">
                        <textarea id="chap_content" name="chap_content" >{$chapitre[0]->chap_content}</textarea>
                        <script type="text/javascript">
                            {literal}CKEDITOR.replace( 'chap_content', {width:'600px', toolbar:'AOToolbar'}) ;{/literal}
                        </script>
                    </dd>
                  </dl>

                  <dl style="height:auto">
                    <dt><label>Illustrations stockées : </label></dt><br />
                                      
                    <!-- photos  -->
                    <div class="wrap">
                        <div class="p1">
                            <input type="hidden" name="photo-annonce" value="{if isset($chapImg)}{foreach $chapImg as $key=>$item}{if ($key >0)},{/if}{$item}{/foreach}{/if}" id="photo-annonce" />
                            <div class="upload_image">
                                <img src="{$j_basepath}design/front/images/no_image.jpg" id="thumb" alt="no image"/>
                                <!--chemin du fichier-->
                                <input type="text" id="fic" name="fic"  class="nom" readonly="true" value=""/>
                                <!-- Upload Button-->
                                <div id="upload" class='btn_upload'>Parcourir</div>
                                <span id="status" >
                                    <img src="{$j_basepath}design/front/images/loading.gif" class="loading"  alt="no image"/>
                                    <p></p>
                                </span> 
                            </div>
                            <!-- open kcfinder -->
                            <input type="hidden" value="{$path_img}" id="path_img" />
                            {literal}
                            <script type="text/javascript">
                                function str_replace (search, replace, subject, count) {
 
                                  var i = 0,
                                    j = 0,
                                    temp = '',
                                    repl = '',
                                    sl = 0,
                                    fl = 0,
                                    f = [].concat(search),
                                    r = [].concat(replace),
                                    s = subject,
                                    ra = Object.prototype.toString.call(r) === '[object Array]',
                                    sa = Object.prototype.toString.call(s) === '[object Array]';
                                  s = [].concat(s);
                                  if (count) {
                                    this.window[count] = 0;
                                  }

                                  for (i = 0, sl = s.length; i < sl; i++) {
                                    if (s[i] === '') {
                                      continue;
                                    }
                                    for (j = 0, fl = f.length; j < fl; j++) {
                                      temp = s[i] + '';
                                      repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
                                      s[i] = (temp).split(f[j]).join(repl);
                                      if (count && s[i] !== temp) {
                                        this.window[count] += (temp.length - s[i].length) / f[j].length;
                                      }
                                    }
                                  }
                                  return sa ? s : s[0];
                                }

                                function openKCFinder(field) 
                                {
                                    img_path = $("#path_img").val();
                                    window.KCFinder = {
                                        callBack: function(url) {
                                            var url = str_replace("%20"," ",url) ;
                                            window.KCFinder = null;
                                            // field.value = url;
                                            field.val(url) ;
                                            addImageinCarousel(url);
                                        }
                                    };
                                    
                                    window.open(j_basepath+'kcfinder/browse.php?type=images&dir='+ img_path, 'kcfinder_textbox',
                                        'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
                                        'resizable=1, scrollbars=0, width=800, height=600'
                                    );
                                }
                                $(function(){
                                    var cible = $('#fic');
                                    imageName = cible.val();
                                    $('#upload').click(function(){
                                        openKCFinder (cible) ;
                                    });
                                    
                                });
                            </script>
                            {/literal}
                            <!-- fin kcfinder -->

                        </div>

                        <!--begin gallery-->
                       <div class="infiniteCarousel">
                            <div class="wrapper">
                                <ul>
                                    {if isset($chapImg)}
                                        {foreach $chapImg as $item2}
                                             <li>
                                                    <img src="{$item2}" title="{$item2}" width="84" />
                                                    <img src="{$j_basepath}design/front/images/DeleteRed.png" class="deleteImage" title="Supprimer cette image" />
                                             </li>
                                        {/foreach}
                                    {/if}
                                </ul>        
                            </div>
                        </div>
                        <!--end gallery-->

                        <div class="clear">&nbsp;</div>
                    </div>
                    <!-- finphotos  -->
                    
                  </dl>
                  
                    
                 <dl class="submit">
                   <input class="valider" title="Valider" type="submit" value="" />
                   <a title="Annuler" href="{jurl 'essais~BoModele:index', array('iId'=>$oEssai->ess_id), false}" class="bt_green" ><span class="bt_green_lft"></span><strong>Annuler</strong><span class="bt_green_r"></span></a>
                 </dl>  

            </form>
        </div><!-- end of right content-->

             
        </div>   <!--end of center content -->               

        <div class="clear"></div>
    </div> <!--end of main content-->
    
    
    <div class="footer">
    </div>

</div>      
